<template>
  <div class="oe-exam-manage" v-loading="loading">
    <top-tip v-if="batchTitle" :title="titleList" :batchTitle="batchTitle"></top-tip>
    <div class="oe-exam-content">
      <div class="oe-manage-search">
        <div class="oe-manage-lis">
          <span class="oe-manage-text">考试名称：</span>
          <span class="oe-manage-input" style="width: 200px; margin-right: 10px">
            <a-input placeholder="输入考试名称" v-model="examName" @keyup.13="searchList" />
          </span>
        </div>
        <div class="oe-manage-lis">
          <span class="oe-manage-text">&nbsp;&nbsp;&nbsp;&nbsp;分类名称：</span>
          <span class="oe-manage-input" style="width: 200px">
            <a-input placeholder="输入分类名称" v-model="sortName" @keyup.13="searchList" />
          </span>
          <span style="display: inline-block;width: 15px;"></span>
        </div>
        <div class="oe-manage-lis" v-if="sysType != 2">
          <span class="oe-manage-text">&nbsp;&nbsp;&nbsp;&nbsp;发布状态：</span>
          <span class="oe-manage-select">
            <a-select v-model="selectType" style="width: 120px">
              <a-select-option value="全部">全部</a-select-option>
              <a-select-option value="1">已发布</a-select-option>
              <a-select-option value="0">未发布</a-select-option>
              <a-select-option value="-1">未设置题目</a-select-option>
            </a-select>
          </span>
          <span style="display: inline-block;width: 15px;"></span>
        </div>
        <div class="oe-manage-lis" v-if="sysType != 2">
          <span class="oe-manage-text">&nbsp;&nbsp;&nbsp;&nbsp;考试状态：</span>
          <span class="oe-manage-select">
            <a-select v-model="timeType" style="width: 120px">
              <a-select-option value="全部">全部</a-select-option>
              <a-select-option value="2">已结束</a-select-option>
              <a-select-option value="1">进行中</a-select-option>
              <a-select-option value="0">未开始</a-select-option>
            </a-select>
          </span>
          <span style="display: inline-block;width: 15px;"></span>
        </div>
        <div class="oe-manage-lis" v-if="sysType != 2">
          <span class="oe-manage-text" v-if="examMode == 2">&nbsp;&nbsp;&nbsp;&nbsp;考试方式：</span>
          <span class="oe-manage-select" v-if="examMode == 2">
            <a-select v-model="examType" style="width: 120px">
              <a-select-option value="全部">全部</a-select-option>
              <a-select-option value="0">线上考试</a-select-option>
              <a-select-option value="1">线下考试</a-select-option>
            </a-select>
          </span>
          <span style="display: inline-block;width: 15px;"></span>
        </div>
        <div class="oe-manage-lis">
          <span class="oe-manage-btns">
            <a-button type="primary" @click.stop="searchList">查询</a-button>
          </span>
        </div>
      </div>
      <div class="oe-manage-fns">
        <a-button @click="checkAllAction">{{ checkAll ? '取消全选' : '全选' }}</a-button>
        <!-- <a-button
          icon="plus"
          type="primary"
          @click.stop="addExam()"
          v-if="operationList.includes('add/edit/del')"
        >新增考试</a-button>-->
        <a-button
          icon="plus"
          type="primary"
          @click.stop="addExamOne()"
          v-if="IsShowOneAddExam && isShowTestSchool && operationList.includes('add/edit/del')"
        >新增考试</a-button>
        <a-button
          @click="cancelExam(0, 0)"
          v-if="operationList.includes('发布考试') && IsShowCancelPublic && sysType != 2"
        >取消发布</a-button>
        <a-button
          @click="carryStudent"
          v-if="operationList.includes('add/edit/del:stu') && isShowAddStu  && sysType != 2"
        >同步学生</a-button>
        <a-button @click="deleteExam(0)" v-if="operationList.includes('add/edit/del')">批量删除</a-button>
        <a-button @click="setMenber(1)" v-if="operationList.includes('设置白名单')  && sysType == 0">设置白名单</a-button>
        <a-button @click="setMenber(2)" v-if="operationList.includes('设置黑名单') && false">设置黑名单</a-button>
        <a-button @click="sendEmail(0)" v-if="operationList.includes('add/edit/del')  && sysType != 2">邮件通知</a-button>
        <a-button
          @click="fenpeiModel = true"
          v-if="operationList.includes('一键分配座位号') && examMode != 0 && sysType == 0"
        >一键分配座位号</a-button>
        <a-button
          @click="setStuCard(0)"
          v-if="operationList.includes('一键分配座位号') && examMode != 0 && sysType == 0"
        >准考证</a-button>
      </div>
      <div class="oe-exam-container">
        <a-checkbox-group @change="onChange" v-model="defaultCheck">
          <a-checkbox :value="exam.Id" v-for="exam in examList" :key="exam.Id">
            <div
              class="oe-exam-item"
              :style="{ background: exam.IsOver && exam.RepairType != 1 && exam.RepairType != 2 ? '#fff' : '#fff' }"
            >
              <div class="oe-item-top">
                <span class="oe-item-split"></span>
                <span class="oe-item-label">{{ exam.Title }}</span>
                <span
                  v-if="exam.RepairType == 0 &&  sysType != 2"
                  :class="[
                    'oe-exam-status',
                    exam.SetTime
                      ? exam.IsOver
                        ? 'color-end'
                        : 'color-push'
                      : !exam.IsHasQues
                      ? 'color-danger'
                      : 'color-danger'
                  ]"
                >
                  <i
                    v-if="exam.RepairType == 0"
                    :class="[
                      'iconfont',
                      exam.SetTime
                        ? exam.IsOver
                          ? 'icon-yijieshu'
                          : 'icon-dui'
                        : !exam.IsHasQues
                        ? 'icon-jingshi1'
                        : 'icon-jingshi1'
                    ]"
                  ></i>
                  {{ exam.SetTime ? (exam.IsOver ? '已结束' : exam.IsStart ? '已发布' + exam.CheckType : '已发布'+ exam.CheckType) : !exam.IsHasQues ? '未设置题目' : '未发布' }}
                  <span
                    v-if="exam.SetTime && (exam.SynchronizedAnswers == 0 || exam.RepairSynchronizedAnswers == 0)"
                  >【答案未同步】</span>
                </span>
                <span
                  v-else :class="['oe-exam-status', !exam.IsHasQues ? 'color-danger' : 'color-push']"
                >
                  <i v-if="exam.RepairType == 0" :class="['iconfont',!exam.IsHasQues ? 'icon-jingshi1' : exam.CheckType ? 'icon-dui' : '']"></i>
                  {{ !exam.IsHasQues ? '未设置题目' : exam.CheckType ? exam.CheckType : '' }}
                  <span
                    v-if="exam.SetTime && (exam.SynchronizedAnswers == 0 || exam.RepairSynchronizedAnswers == 0)"
                  >【答案未同步】</span>
                </span>
                <span
                  v-if="exam.RepairType != 0 &&  sysType != 2"
                  :class="[
                    'oe-exam-status',
                    exam.RepairType == 3
                      ? 'color-end'
                        : 'color-push'
    
                  ]"
                >
                  <i
                    v-if="exam.RepairType != 0"
                    :class="[
                      'iconfont',
                      exam.RepairType == 3
                        ? 'icon-yijieshu'
                          : 'icon-dui'
                    ]"
                  ></i>
                  {{ exam.RepairType == 1 ? '补考已发布' : exam.RepairType == 2 ? '补考已发布' : '补考已结束' }}
                  <span
                    v-if="exam.SetTime && (exam.SynchronizedAnswers == 0 || exam.RepairSynchronizedAnswers == 0)"
                  >【答案未同步】</span>
                </span>
                <span class="oe-item-right" @click.stop.prevent>
                  <span
                    class="oe-btn"
                    @click.stop.prevent="setExamStep(exam)"
                    v-if="IsShowOneAddExam && isShowTestSchool"
                  >
                    <i class="iconfont icon-canyu"></i>
                    <span class="oe-btn-text">编辑考试</span>
                  </span>
                  <span
                    class="oe-btn"
                    @click.stop.prevent="getReviewPaper(exam)"
                    v-if="operationList.includes('预览试卷') && exam.IsHasQues"
                  >
                    <i class="iconfont icon-chakan"></i>
                    <span class="oe-btn-text">预览试卷</span>
                  </span>
                  <!-- <span
                    class="oe-btn"
                    key="10"
                    @click.stop.prevent="examRoom(exam, 'add/edit/del:room')"
                    v-if="operationList.includes('add/edit/del:room') && exam.ExamMode"
                  >
                    <i class="iconfont icon-kaochangguanli"></i>
                    <span class="oe-btn-text">设置考场</span>
                  </span>
                  <span
                    class="oe-btn"
                    @click.stop.prevent="examBtnsAction(1, '发布考试', exam)"
                    v-if="operationList.includes('发布考试') && exam.IsHasQues"
                  >
                    <i class="iconfont icon-fabu-bold"></i>
                    <span class="oe-btn-text">发布考试</span>
                  </span>-->
                  <span
                    class="oe-btn"
                    @click.stop.prevent="examBtnsAction(2, '监考管理', exam)"
                    v-if="(operationList.includes('监考管理') || isXK) && exam.SetTime   && !exam.ExamMode &&  sysType == 0"
                  >
                    <i class="iconfont icon-shipinjiankao"></i>
                    <span class="oe-btn-text">监考管理</span>
                  </span>
                  <span
                    class="oe-btn"
                    @click.stop.prevent="getExamAnalysis(exam)"
                    v-if="exam.IsOver && operationList.includes('考试分析') &&  sysType != 2"
                  >
                    <i class="iconfont icon-kaoshifenxi"></i>
                    <span class="oe-btn-text">考试分析</span>
                  </span>
                  <a-dropdown v-if="isNoOption" overlayClassName="drop-icon">
                    <span class="ant-dropdown-link">
                      操作
                      <a-icon type="down" />
                    </span>
                    <a-menu slot="overlay">
                      <!-- <a-menu-item
                        key="0"
                        @click="getDropAction($event, exam, 'add/edit/del')"
                        v-if="exam.IsMy && operationList.includes('add/edit/del')"
                      >
                        <i class="iconfont icon-edit"></i>
                        编辑信息
                      </a-menu-item>
                      <a-menu-item
                        key="1"
                        @click="getDropAction($event, exam, 'add/edit/del:stu')"
                        v-if="operationList.includes('add/edit/del:stu')"
                      >
                        <i class="iconfont icon-xueshengguanli" style="margin: 0px;"></i>
                        考生管理
                      </a-menu-item>
                      <a-menu-item
                        key="2"
                        @click="getDropAction($event, exam, 'add/edit/del:monitor')"
                        v-if="operationList.includes('add/edit/del:monitor')  && !exam.ExamMode"
                      >
                        <i class="iconfont icon-jiaoshi"></i>
                        监考教师
                      </a-menu-item>
                      <a-menu-item
                        key="3"
                        @click="getDropAction($event, exam, 'add/edit/del:mark')"
                        v-if="operationList.includes('add/edit/del:mark')"
                      >
                        <i class="iconfont icon-jiashi"></i>
                        批阅教师
                      </a-menu-item>
                      <a-menu-item
                        key="4"
                        @click="getDropAction($event, exam, '设置题目')"
                        v-if="operationList.includes('设置题目')"
                      >
                        <i class="iconfont icon-shezhi1"></i>
                        设置题目
                      </a-menu-item>-->
                      <!-- <a-menu-item
                        key="10"
                        @click="getDropAction($event, exam, '考场管理')"
                        v-if="operationList.includes('考场管理') && exam.ExamMode"
                      >
                        <i class="iconfont icon-kaochangguanli"></i>
                        考场管理
                      </a-menu-item>-->
                      <a-menu-item
                        key="8"
                        @click="getDropAction($event, exam, '设置白名单')"
                        v-if="operationList.includes('设置白名单')   && !exam.ExamMode &&  sysType != 2"
                      >
                        <i class="iconfont icon-baimingdan"></i>
                        白名单
                      </a-menu-item>
                      <a-menu-item
                        key="9"
                        @click="getDropAction($event, exam, '黑名单')"
                        v-if="operationList.includes('黑名单') && false"
                      >
                        <i class="iconfont icon-heimingdan"></i>
                        黑名单
                      </a-menu-item>
                      <a-menu-item
                        key="5"
                        @click="getDropAction($event, exam, '审核')"
                        v-if="operationList.includes('审核') && exam.IsNeedCheck && exam.IsHasQues"
                      >
                        <i class="iconfont icon-xiaodui"></i>
                        审核
                      </a-menu-item>
                      <a-menu-item
                        key="6"
                        @click="getDropAction($event, exam, 'add/edit/del:stu')"
                        v-if="operationList.includes('add/edit/del:stu') && exam.IsShowRepairStu &&  sysType != 2"
                      >
                        <i class="iconfont icon-bukao"></i>
                        补考
                      </a-menu-item>
                      <a-menu-item
                        key="14"
                        @click="getDropAction($event, exam, '发布考试')"
                        v-if="operationList.includes('发布考试') && exam.IsHasQues && exam.SetTime == 1 && (exam.SynchronizedAnswers == 0 || exam.RepairSynchronizedAnswers == 0) && (!exam.IsStart || exam.IsOver)"
                      >
                        <i class="iconfont icon-shezhi1"></i>
                        同步答案
                      </a-menu-item>
                      <!-- <a-menu-item
                        key="7"
                        @click="getDropAction($event, exam, '删除')"
                        v-if="!exam.IsOver && exam.IsMy && operationList.includes('删除')"
                      >
                        <i class="iconfont icon-delete"></i>
                        删除
                      </a-menu-item>-->
                      <a-menu-item
                        key="11"
                        @click="getDropAction($event, exam, '封存',)"
                        v-if="operationList.includes('封存')"
                      >
                        <i class="iconfont icon-bukao"></i>
                        <span v-if="exam.SaveKeepType == 1">解封</span>
                        <span v-else>封存</span>
                      </a-menu-item>
                      <a-menu-item
                        key="12"
                        @click="setMenber(3,exam.Id)"
                        v-if="operationList.includes('管理角色')"
                      >
                        <i class="iconfont icon-jiaoseguanli"></i>
                        管理角色
                      </a-menu-item>
                      <!-- <a-menu-item
                        key="13"
                        @click="getDropAction($event, exam, '归档')"
                        v-if="exam.IsOver && operationList.includes('归档')"
                      >
                        <i class="iconfont icon-jiaoseguanli"></i>
                        归档
                      </a-menu-item>-->
                    </a-menu>
                  </a-dropdown>
                </span>
              </div>
              <div class="oe-item-content">
                <div class="oe-item-info fr" v-if="exam.State == 1">
                  <i class="iconfont icon-fengcunbingan" style="font-size: 22px"></i>
                  已归档
                </div>
                <div class="oe-item-info fr" v-else-if="exam.SaveKeepType == 1">
                  <i class="iconfont icon-fengcunbingan" style="font-size: 22px"></i>
                  已封存
                </div>
                <div class="oe-item-line" v-if="sysType != 2">正考时间： {{ exam.StartTime }} -- {{ exam.EndTime }}</div>
                <div  v-if="sysType != 2"
                  class="oe-item-line"
                >补考时间： {{ exam.RepairStartTime }} -- {{ exam.RepairEndTime }}</div>
                <div class="oe-item-line">
                  <div class="oe-line-left">创建人：{{ exam.CreatorName || '--' }}</div>
                  <div class="oe-line-left oe-line-centent">负责教师：{{ exam.TeacherName || '--' }}</div>
                  <div class="oe-line-right">所属分类：{{ exam.SortName || '--' }}</div>
                </div>
                <div class="oe-item-line"  v-if="sysType != 2">
                  <div class="oe-line-left">正考时长：{{ exam.timeLength }}</div>
                  <div class="oe-line-left">补考时长：{{ exam.timeRepairLength }}</div>
                  <!-- <div class="oe-line-left">考试方式：{{ exam.ExamMode ? "线下考试" : "线上考试" }}</div> -->
                  <div class="oe-line-left"  v-if="sysType == 0">
                    考试方式：
                    <span v-if="exam.ExamMode">线下考试</span>
                    <span v-else>线上考试</span>
                  </div>
                </div>
                <div style="width: calc(100% - 220px);">要求：{{ exam.Remark || '暂无要求' }}</div>
              </div>
              <div
                class="oe-item-status"
                v-if="exam.SetTime && exam.IsStart && operationList.includes('批阅列表')"
              >
                <a-tooltip>
                  <template slot="title">已批列表</template>
                  <span
                    class="oe-status-right"
                    @click.stop.prevent="lookDetail(1, exam)"
                  >已批：{{ exam.MarkedCount || 0 }}</span>
                </a-tooltip>
                <a-tooltip>
                  <template slot="title">未批列表</template>
                  <span
                    class="oe-status-unright"
                    @click.stop.prevent="lookDetail(2, exam)"
                  >未批：{{ exam.UnMarkCount || 0 }}</span>
                </a-tooltip>
                <a-tooltip>
                  <template slot="title">未交列表</template>
                  <span
                    class="oe-status-uncommit"
                    @click.stop.prevent="lookDetail(3, exam)"
                  >未交：{{ exam.UnSubmitCount || 0 }}</span>
                </a-tooltip>
              </div>
            </div>
          </a-checkbox>
        </a-checkbox-group>
        <blank-tips v-if="!examList.length"></blank-tips>
        <div class="oe-item-pagenation">
          <a-pagination
            :pageSizeOptions="pageSizeOptions"
            :showSizeChanger="true"
            v-model="pagenation.current"
            :total="pagenation.total"
            :pageSize="pagenation.pageSize"
            :showTotal="(total) => `共 ${total} 条`"
            @showSizeChange="changePage"
            @change="changePage"
          />
        </div>
      </div>
    </div>
    <a-modal
      title="一键分配座位号"
      class="oe-student"
      :visible="fenpeiModel"
      width="40%"
      :closable="false"
    >
      <div class="oe-select">
        <span class="oe-manage-select" style="color:red">
          <h3>分配座位号之前，请仔细阅读一下提示：</h3>
          <div>1、一键分配座位号会给学生分配考场，考试时间，座位号等信息</div>
          <div>2、给学生分配座位号之后，在考试开始之前还可以重新分配，重新分配后，准考证需要重新打印</div>
          <div>3、如果学生没有分配考场，在考场充足的情况下，一键分配座位号会给学生分配考场，反之则不分配</div>
          <div>4、如果分配座位号之后，添加了新的考生，需要重新分配座位号，否则新添加的考生没有座位号信息</div>
          <div>5、一键分配座位号将会分配所有的线下考试</div>
          <div>6、线上考试无需按此操作</div>
          <br />
          <br />
          <a-checkbox value="IsAllowMark" v-model="IsAllowMark">我已阅读并已知晓以上内容</a-checkbox>
        </span>
      </div>
      <template slot="footer">
        <a-button
          type="primary"
          @click="saveStuSet(0)"
          :loading="uploading"
          style="margin-top: 16px"
        >分配座位号</a-button>
        <!-- <a-button
          type="primary"
          @click="saveStuSet(1)"
          :loading="uploading"
          style="margin-top: 16px"
        >分配补考卷</a-button>-->
        <a-button @click.stop="fenpeiModel = false" :loading="uploading">取消</a-button>
      </template>
    </a-modal>
    <a-modal title="邮件通知" class="oe-student" :visible="lookStuCard" width="40%" :closable="false">
      <div class="oe-select">
        <span class="oe-manage-select">
          <h3>温馨提示：</h3>
          <div>1、"通知考生" 会给该考试的考生发送一封邮件，提醒学生进行考试</div>
          <div>2、"通知审核教师" 会给审核考试的第一位教师发送一封邮件，第一位教师审核通过后，会给第二位教师发送等</div>
        </span>
      </div>
      <template slot="footer">
        <a-button
          type="primary"
          @click="sendEmailForPeople(0)"
          :loading="uploading"
          style="margin-top: 16px"
        >通知考生</a-button>
        <a-button
          type="primary"
          @click="sendEmailForPeople(1)"
          :loading="uploading"
          style="margin-top: 16px"
        >通知审核教师</a-button>
        <a-button @click.stop="lookStuCard = false" :loading="uploading">取消</a-button>
      </template>
    </a-modal>
    <a-modal
      title="取消发布"
      class="oe-student"
      :visible="cancelPublish"
      width="500px"
      :closable="false"
    >
      <div class="oe-select">
        <span class="oe-manage-select">
          <h3>温馨提示：</h3>
          <div>1、线下考试取消发布后，需要重新分配座位号</div>
          <div>2、已经有作答学生的考试不允许取消发布</div>
          <div>3、取消发布后，学生将不能看到该考试</div>
        </span>
      </div>
      <template slot="footer">
        <a-button type="primary" @click="cancelMian(0, 0)" style="margin-top: 16px">取消发布正式卷</a-button>
        <a-button type="primary" @click="cancelMian(0, 1)" style="margin-top: 16px">取消发布补考卷</a-button>
        <a-button @click.stop="cancelPublish = false">取消</a-button>
      </template>
    </a-modal>
    <a-modal
      title="选择监考试卷"
      class="oe-select-block"
      :visible="choice"
      @cancel="addCancel"
      :footer="null"
      centered
    >
      <span class="oe-block-btn" @click="choicePaper(0)">正式卷</span>
      <span class="oe-block-btn" @click="choicePaper(1)">补考卷</span>
    </a-modal>
    <a-modal
      title="试卷审核"
      class="oe-exam-modal"
      centered
      v-model="visible"
      :afterClose="closeHandler"
    >
      <a-steps direction="vertical" size="small">
        <a-step
          v-for="audit in auditList"
          :key="audit.TeacherId"
          :title="`${audit.DisplayName}(${audit.CheckTypeString})`"
          :sub-title="audit.CheckDateCreated"
          :description="audit.CheckRemarks"
          :status="checkStep(audit.CheckType)"
        />
      </a-steps>
      <div class="oe-exam-radio" v-if="isMine">
        审核试卷：
        <a-radio-group v-model="chooseRadio">
          <a-radio :value="1" :disabled="!isCanEditAudit">通过</a-radio>
          <a-radio :value="2" :disabled="!isCanEditAudit">不通过</a-radio>
        </a-radio-group>
      </div>
      <div class="oe-exam-textarea" v-if="isMine">
        <span class="oe-exam-text">修改意见：</span>
        <a-input
          type="textarea"
          :rows="5"
          resize="none"
          v-model="option"
          :disabled="!isCanEditAudit"
          class="oe-textarea-item"
          placeholder="若审核不通过，必须填写试卷的修改意见"
        ></a-input>
      </div>
      <div slot="footer">
        <a-button type="primary" @click.stop="sureRight" v-if="isMine">确认</a-button>
        <a-button @click.stop="visible = false">取消</a-button>
      </div>
    </a-modal>
    <a-modal title="同步学生" width="65%" class="oe-exam-table-modal" centered v-model="tableVisible">
      <div class="oe-exam-table-input">
        批次名称：
        <a-input v-model="searchExamBatch" placeholder="请输入批次名称" @keyup.13="getCarryList"></a-input>考试名称：
        <a-input v-model="searchExam" placeholder="请输入考试名称" @keyup.13="getCarryList"></a-input>发布状态：
        <a-select v-model="tableSelect" style="width: 120px">
          <a-select-option value="全部">全部</a-select-option>
          <a-select-option value="是">已发布</a-select-option>
          <a-select-option value="否">未发布</a-select-option>
        </a-select>

        <a-button type="primary" @click="getCarryList">查询</a-button>
      </div>
      <div class="oe-exam-table-table">
        <a-table
          :columns="columns"
          :dataSource="dataList"
          :pagination="paginationObj"
          @change="onTableChange"
          :rowSelection="rowSelection"
          :scroll="{ y: 400 }"
        ></a-table>
      </div>
      <div slot="footer">
        <a-button type="primary" @click="sureCarry">确认</a-button>
        <a-button @click.stop="tableVisible = false">取消</a-button>
      </div>
    </a-modal>
    <a-modal
      :title="setTitle"
      width="50%"
      class="oe-set-menber-modal"
      centered
      v-model="setMenberVisible"
      :afterClose="setClose"
    >
      <div class="oe-set-info">
        <div class="oe-set-info-title">
          <a-icon type="info-circle" theme="filled" />只有已添加到IP白名单可以进行考试
        </div>
        <p>- 可以填写IP地址（如192.168.0.1）或IP段（如192.168.0.0-192.168.0.24）</p>
        <p>- 多个IP需要用英文逗号隔开，如192.168.0.1,192.168.0.0-192.168.0.24</p>
        <p>- 没有设置白名单则默认所有的IP都可以访问</p>
      </div>
      <div class="oe-set-textarea">
        <a-input
          placeholder="请输入要设置的地址"
          type="textarea"
          :autosize="{ minRows: 4, maxRows: 6 }"
          v-model="setIps"
        ></a-input>
      </div>
      <div slot="footer">
        <a-button type="primary" @click="sureSet">确认</a-button>
        <a-button @click.stop="setMenberVisible = false">取消</a-button>
      </div>
    </a-modal>
    <a-modal
      :title="saveTitle"
      width="50%"
      class="oe-set-menber-modal"
      centered
      v-model="setSaveKeepType"
      :afterClose="setClose"
    >
      <div class="oe-set-info clearfix">
        <div class="oe-set-info-title fl">
          <small class="oe-ser-info-small">
            <p>1、试卷封存后，任何人都不能预览</p>
            <p>2、只有监考教师和管理员可以解封，其中监考教师需要输入激活码</p>
            <p>3、所有封存、解封的记录将会在右侧展示</p>
          </small>
          <a-icon type="info-circle" theme="filled" />
          封存激活码：{{ saveKeepCode }}
          <a-button type="primary" @click="getCode">更新</a-button>
          <small class="oe-ser-info-small">
            <p>
              当前试卷状态为：
              <span v-if="saveKeepType == 0">解封状态</span>
              <span v-if="saveKeepType == 1">封存状态</span>
            </p>
          </small>
        </div>
        <div class="fr" style="height:84px;overflow: auto;padding-right: 10px;">
          <div v-for="(item,index) in saveKeepList" :key="index">
            <span style="color:#1890ff;margin-right: 5px;">{{item.SaveKeepName}}</span>在
            <span>{{item.DateCreated}}</span>对该试卷进行
            <span
              style="color:#67c23a;margin-left: 5px;"
              v-if="item.SaveKeepType == '解封'"
            >{{item.SaveKeepType}}</span>
            <span style="color:#dd514c;margin-left: 5px;" v-else>{{item.SaveKeepType}}</span>
          </div>
        </div>
      </div>

      <div slot="footer">
        <a-button type="primary" @click="sureSetKeepType('0')" v-if="saveKeepType == 1">解封</a-button>
        <a-button type="primary" @click="sureSetKeepType('1')" v-else>封存</a-button>
        <a-button @click.stop="setSaveKeepType = false">取消</a-button>
      </div>
    </a-modal>
    <a-modal
      title="设置角色"
      class="oe-student"
      :visible="addRole"
      width="500px"
      @cancel="addRoleCancel"
    >
      <div class="oe-select">
        <span class="oe-manage-select">
          <h3>温馨提示：</h3>
          <div>1、选择相应的考试，增加管理角色，可以增加多个角色</div>
          <div>2、设置角色后，该角色下的成员就可以按照分配的权限进行管理相应的考试</div>
        </span>
      </div>
      <div class="oe-select">
        <span class="oe-modal-input">
          <a-select
            mode="multiple"
            style="width: 100%"
            showSearch
            :allowClear="true"
            v-model="CreateName"
            optionFilterProp="children"
            @change="selectTeacher"
            placeholder="请输入角色姓名查询"
          >
            <a-select-option
              v-for="item in selection"
              :index="index"
              :key="item.Id"
            >{{ item.RoleName }}</a-select-option>
          </a-select>
        </span>
      </div>
      <template slot="footer">
        <a-button type="primary" @click="saveRole()" style="margin-top: 16px">保存</a-button>
        <a-button @click.stop="addRoleCancel()">取消</a-button>
      </template>
    </a-modal>
    <a-modal
      title="同步考试答案"
      class="oe-student"
      :visible="saveExamAnswer"
      width="500px"
      :closable="false"
    >
      <div class="oe-select">
        <span class="oe-manage-select">
          <h3>温馨提示：</h3>
          <div>1、同步考试答案后，预览试卷就可以看到题目答案</div>
          <div>2、只有发布考试后，并且不是考试作答时间内可以进行同步</div>
          <div>3、只有同步考试答案后，才可以进行批阅学生作答记录</div>
          <div>4、同步考试答案只同步当前考试发布时使用的试卷</div>
          <div>5、同步考试答案是不可逆的，同步后不可以取消</div>
        </span>
      </div>
      <template slot="footer">
        <a-button
          v-if="repairSynchronizedAnswers == 1 && synchronizedAnswers == 0"
          type="primary"
          @click="saveExamQuesAnswer(0)"
          style="margin-top: 16px"
        >同步答案</a-button>
        <a-button
          v-if="repairSynchronizedAnswers == 0 && synchronizedAnswers == 0"
          type="primary"
          @click="saveExamQuesAnswer(0)"
          style="margin-top: 16px"
        >同步正式卷答案</a-button>
        <a-button
          v-if="repairSynchronizedAnswers == 0"
          type="primary"
          @click="saveExamQuesAnswer(1)"
          style="margin-top: 16px"
        >同步补考卷答案</a-button>
        <a-button @click.stop="saveExamAnswer = false">取消</a-button>
      </template>
    </a-modal>
  </div>
</template>

<script>
import topTip from '@/components/top-tip/index.vue';
import blankTips from '@/components/blank-tips/index.vue';
import GetOperationList from '@/lib/mixin/methods.js';
export default {
  name: 'examManage',
  mixins: [GetOperationList],
  components: {
    topTip,
    blankTips
  },
  data() {
    return {
      examQuesAnswerId: '',
      synchronizedAnswers: 1,
      repairSynchronizedAnswers: 1,
      saveExamAnswer: false,
      titleList: [{ text: '批次(考试)管理' }, { text: '考试管理', color: '#1890ff' }],
      examName: '', //考试名称
      sortName: '',
      selectType: '全部', //选择的类型
      examType: '全部',
      timeType: '全部',
      // 考试列表
      examList: [],
      // 默认选择列表
      defaultCheck: [],
      // 是否全选
      checkAll: false,
      visible: false,
      // 默认选择的值
      chooseRadio: 1,
      option: '',
      isDisabled: true,
      // 分页数据
      pagenation: {
        current: 1,
        pageSize: 10,
        total: 0
      },
      pageSizeOptions: ['10', '20', '50', '100', '1000'],
      loading: false,
      tableVisible: false,
      // 考试名称
      searchExam: '',
      searchExamBatch: '',
      fenpeiModel: false,
      lookStuCard: false,
      uploading: false,
      cancelPublish: false,
      // 分页配置
      paginationObj: {
        pageSizeOptions: ['10', '20', '50', '100', '1000'],
        showQuickJumper: true,
        showSizeChanger: true,
        showTotal(total) {
          return `共 ${total} 条`;
        },
        onShowSizeChange: (current, pageSize) => {
          this.paginationObj.current = current;
          this.paginationObj.pageSize = pageSize;
        },
        onChange: (current, pageSize) => {
          // this.getExamList(current, pageSize);
          this.paginationObj.current = current;
          this.paginationObj.pageSize = pageSize;
        },
        buildOptionText(props) {
          return props.value + '条/页';
        },
        current: 1,
        pageSize: 10,
        total: 0
      },
      // 表标题
      columns: [
        {
          title: '序号',
          dataIndex: 'Number',
          width: '10%',
          key: 'Number'
        },
        {
          title: '批次名称',
          dataIndex: 'BatchName',
          width: '15%',
          key: 'BatchName',
          sorter: true
        },
        {
          title: '考试名称',
          dataIndex: 'Title',
          width: '15%',
          key: 'Title',
          sorter: true
        },
        {
          title: '考试时间',
          dataIndex: 'time',
          width: '20%',
          key: 'time',
          sorter: true
        },
        {
          title: '负责教师名称',
          dataIndex: 'TeacherName',
          width: '12%',
          key: 'TeacherName',
          sorter: true
        },
        {
          title: '学生数量',
          dataIndex: 'StudentCount',
          width: '13%',
          key: 'StudentCount',
          sorter: true
        },
        {
          title: '创建时间',
          dataIndex: 'DateCreated',
          width: '15%',
          key: 'DateCreated',
          sorter: true
        }
      ],
      // 数据列表
      dataList: [],
      //选择正式卷还是补考卷进行监考（当两份试卷都存在时则进行选择切换）
      choice: false,
      selectedRowKeys: [],
      // 选中的考试
      selectedRow: [],
      // 同步考试选择
      tableSelect: '全部',
      // 操作List
      operationList: [],
      // 、操作list
      IsOpList: [],
      // 缓存校对的考试
      sureRightItem: '',
      newPage: '',
      setTitle: '设置白名单',
      saveTitle: '封存考试',
      setMenberVisible: false,
      setSaveKeepType: false,
      chooseExamId: '',
      setIps: '',
      saveKeepType: '',
      saveKeepCode: '',
      // 点击的考试
      clickExam: '',
      //试卷切换Id
      paperId: '',
      isXK: false,
      addRole: false,
      selection: [],
      CreateName: [],
      mainTeacherIds: [],
      saveKeepList: [],
      IsAllowMark: false,
      examMode: 0,
      batchTitle: '',
      auditList: [],
      isCanEditAudit: false,
      IsShowCancelPublic: false,
      isShowAddStu: false,
      isMine: true,
      IsShowOneAddExam: false,
      isShowTestSchool: false,
      sysType:0
    };
  },
  watch: {
    chooseRadio(val) {
      if (val == 1) {
        this.isDisabled = true;
        this.option = '';
      } else {
        this.isDisabled = false;
      }
    },
    selectType(newVal, oldVal) {
      if (newVal !== oldVal) {
        this.getExamList();
      }
    },
    timeType(newVal, oldVal) {
      if (newVal !== oldVal) {
        this.getExamList();
      }
    },
    examType(newVal, oldVal) {
      if (newVal !== oldVal) {
        this.getExamList();
      }
    },
    tableSelect(newVal, oldVal) {
      if (newVal !== oldVal) {
        this.getCarryList();
      }
    }
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      vm.getExamOperation();
    });
  },
  computed: {
    rowSelection() {
      const { selectedRowKeys } = this;
      return {
        selectedRowKeys,
        onChange: this.onSelectChange,
        type: 'radio'
      };
    },
    isNoOption() {
      if (
        this.operationList.includes('管理角色') ||
        this.operationList.includes('封存') ||
        this.operationList.includes('add/edit/del:stu') ||
        this.operationList.includes('审核') ||
        this.operationList.includes('设置白名单')
      ) {
        return true;
      } else {
        return false;
      }
      // if (this.IsOpList.length) {
      //   let flag = false;
      //   for (let i = 0; i < this.IsOpList.length; i++) {
      //     if (this.IsOpList[i].KeyWord == 'txt') {
      //       flag = true;
      //       break;
      //     } else {
      //       flag = false;
      //     }
      //   }
      //   if (flag) {
      //     return true;
      //   } else {
      //     return false;
      //   }
      // } else {
      //   return false;
      // }
    }
  },
  methods: {
    //判断审核状态
    checkStep(status) {
      switch (status) {
        case 0:
          return 'wait';
        case 1:
          return 'finish';
        case 2:
          return 'error';
        default:
          break;
      }
    },
    //一键分配座位号
    saveStuSet(examType, continueDis) {
      if (!this.IsAllowMark) {
        this.$message.warn('请勾选复选框');
        return;
      }
      this.uploading = true;
      this.$http
        .post('/api/design/StuRoom/distributionSeat', {
          batchId: this.$route.params.batchid,
          examType: examType,
          continueDis: continueDis
        })
        .then((rst) => {
          this.uploading = false;
          if (rst.code == 1) {
            this.fenpeiModel = false;
            this.$message.success(rst.msg);
          } else if (rst.code == -100) {
            this.$confirm({
              title: '提示',
              content: '当前批次存在已经开始的考试轮次，需要过滤这些已经开始的轮次吗？',
              centered: true,
              onOk: () => {
                this.saveStuSet(examType, 1);
              }
            });
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    //准考证
    setStuCard(examType) {
      this.$http
        .post('/api/design/student/isSetExamRoom', {
          batchId: this.$route.params.batchid,
          examType: examType
        })
        .then((rst) => {
          if (rst.code > 0) {
            if (examType == 0) {
              if (rst.isSet) {
                this.$router.push({
                  name: 'stuCard',
                  params: {
                    batchid: this.$route.params.batchid,
                    examType: examType
                  }
                });
              } else {
                this.$message.error('当前正考批次未分配座位号，请先分配座位号');
              }
            } else {
              if (rst.isSetRepair) {
                this.$router.push({
                  name: 'stuCard',
                  params: {
                    batchid: this.$route.params.batchid,
                    examType: examType
                  }
                });
              } else {
                this.$message.error('当前补考批次未分配座位号，请先分配座位号');
              }
            }
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    // 关闭modal的回调
    closeHandler() {
      this.chooseRadio = 1;
      this.option = '';
    },
    // 校对
    sureRight() {
      if (this.chooseRadio === 2 && !this.option) {
        this.$message.info('审核不通过，需要填写理由');
        return;
      }
      this.loading = true;
      this.$http
        .post('/api/design/papermanage/setPaperCheck', {
          examId: this.sureRightItem.Id,
          checkType: this.chooseRadio,
          checkRemarks: this.option
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code == 1) {
            this.visible = false;
            this.chooseRadio = 1;
            this.option = '';
            this.getExamList();
            this.$message.success('审核成功');
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    // 判断是否是只读
    getIsWrite(type) {
      let index = this.IsOpList.findIndex((el) => {
        return el.Name === type;
      });
      if (index > -1) {
        if (!this.IsOpList[index].IsRead && !this.IsOpList[index].IsWrite) {
          this.$message.info('您没有该操作权限！');
          return false;
        } else {
          return true;
        }
      }
    },
    // 同步学生
    carryStudent() {
      if (!this.getIsWrite('add/edit/del:stu')) {
        return;
      }
      if (!this.defaultCheck.length) {
        this.$message.error('请先选择你要同步的考试!');
        return;
      }
      this.getCarryList();
    },
    //取消发布
    cancelExam(importId, examType) {
      if (!this.getIsWrite('发布考试')) {
        return;
      }

      if (!importId) {
        if (!this.defaultCheck.length) {
          this.$message.error('请先选择你要取消发布的考试');
          return;
        }
      }
      this.cancelPublish = true;
    },
    //取消发布
    cancelMian(importId, examType) {
      if (!this.getIsWrite('发布考试')) {
        return;
      }

      if (!importId) {
        if (!this.defaultCheck.length) {
          this.$message.error('请先选择你要取消发布的考试');
          return;
        }
      }

      this.$confirm({
        title: '提示',
        content: '确认要取消发布选择的考试吗？',
        centered: true,
        onOk: () => {
          this.loading = true;
          let ids = Array.prototype.slice.call(this.defaultCheck);
          let [...id] = ids;
          this.$http
            .post('/api/design/workexam/cancelPublic', {
              examIds: importId ? importId : id,
              batchId: this.$route.params.batchid,
              examType: examType
            })
            .then((rst) => {
              this.loading = false;
              if (rst.code == 1) {
                this.cancelPublish = false;
                this.defaultCheck = [];
                this.$message.success(rst.msg);
                this.getExamList();
              } else {
                this.$message.error(rst.msg);
              }
            });
        }
      });
    },
    //邮件通知
    sendEmail() {
      if (!this.defaultCheck.length) {
        this.$message.error('请先选择你要发送邮件的考试');
        return;
      }
      this.lookStuCard = true;
    },
    sendEmailForPeople(type) {
      if (!this.defaultCheck.length) {
        this.$message.error('请先选择你要发送邮件的考试');
        return;
      }
      this.$confirm({
        title: '提示',
        content: type == 1 ? '确定要给审核教师发邮件吗？' : '确定要给考生发邮件吗？',
        centered: true,
        onOk: () => {
          this.loading = true;
          let ids = Array.prototype.slice.call(this.defaultCheck);
          let [...id] = ids;
          this.$http
            .post('/api/design/workexam/sendEmail', {
              batchId: this.$route.params.batchid,
              ids: id,
              sendType: type
            })
            .then((rst) => {
              this.loading = false;
              if (rst.code == 1) {
                this.lookStuCard = false;
                this.defaultCheck = [];
                this.$message.success(rst.msg);
              } else {
                this.$message.error(rst.msg);
              }
            });
        }
      });
    },
    // 批量删除考试
    deleteExam(importId) {
      if (!this.getIsWrite('add/edit/del')) {
        return;
      }
      if (!importId) {
        if (!this.defaultCheck.length) {
          this.$message.error('请先选择你要删除的考试');
          return;
        }
      }

      this.$confirm({
        title: '提示',
        content: '确认要删除考试吗？',
        centered: true,
        onOk: () => {
          this.loading = true;
          let ids = Array.prototype.slice.call(this.defaultCheck);
          let [...id] = ids;
          this.$http
            .post('/api/design/workexam/delExam', {
              ids: importId ? importId : id
            })
            .then((rst) => {
              this.loading = false;
              if (rst.code == 1) {
                this.defaultCheck = [];
                this.$message.success(rst.msg);
                this.getExamList();
              } else {
                this.$message.error(rst.msg);
              }
            });
        }
      });
    },
    // 确定同步学生
    sureCarry() {
      this.loading = true;
      let ids = Array.prototype.slice.call(this.defaultCheck);

      if (!this.selectedRow.length) {
        this.$message.error('请选择你要同步的考试!');
        this.loading = false;
        return;
      }
      this.$http
        .post('/api/design/workexam/synchroExam', {
          batchId: this.$route.params.batchid,
          ids: ids,
          id: this.selectedRow[0].Id
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code === 1) {
            this.defaultCheck = [];
            this.$message.success(rst.msg);
            this.tableVisible = false;
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRow = selectedRows;
      this.selectedRowKeys = selectedRowKeys;
    },
    getCarryList(current, pageSize, sorter) {
      this.loading = true;
      let ids = JSON.stringify(Array.prototype.slice.call(this.defaultCheck));
      this.$http
        .post('/api/design/workexam/getStuExamList', {
          title: this.searchExam,
          batchName: this.searchExamBatch,
          setTime: this.tableSelect == '是' ? 1 : this.tableSelect == '否' ? 0 : '',
          batchId: this.$route.params.batchid,
          examIds: this.defaultCheck,
          sort: sorter ? sorter : '',
          pageSize: pageSize ? pageSize : 10,
          page: current ? current : 1
        })
        .then((rst) => {
          this.loading = false;
          this.dataList = [];
          if (rst.code === 1) {
            this.paginationObj.current = rst.pagination.pageIndex;
            this.paginationObj.pageSize = rst.pagination.pageSize;
            this.paginationObj.total = rst.pagination.totalCount;
            if (rst.list.length) {
              rst.list.forEach((item, index) => {
                let time = item.StartTime + '--' + item.EndTime;
                let Number = (rst.pagination.pageIndex - 1) * rst.pagination.pageSize + index + 1;
                this.dataList.push({
                  ...item,
                  time,
                  Number
                });
              });
            }
            // this.dataList = rst.list;
            if (!this.tableVisible) {
              this.tableVisible = true;
            }
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    // 点击table排序
    onTableChange(pagenation, filter, sort) {
      let sortOrder = '';
      if (sort.order) {
        if (sort.order == 'ascend') {
          sortOrder = sort.columnKey;
        } else if (sort.order == 'descend') {
          sortOrder = '-' + sort.columnKey;
        } else {
          sortOrder = '';
        }
      }
      this.getCarryList(pagenation.current, pagenation.pageSize, sortOrder);
    },
    // 获取页面操作
    getExamOperation() {
      this.loading = true;
      this.GetOperationList().then((rst) => {
        this.loading = false;
        this.operationList = [];
        this.IsOpList = [];
        if (rst.code == 1) {
          if (rst.list.length) {
            rst.list.forEach((item) => {
              if (
                item.Name == 'add/edit/del:mark' ||
                item.Name == 'add/edit/del:monitor' ||
                item.Name == 'add/edit/del:room' ||
                item.Name == 'add/edit/del:stu' ||
                item.Name == '设置题目' ||
                item.Name == 'add/edit/del' ||
                item.Name == '发布考试'
              ) {
                this.IsShowOneAddExam = true;
              }
              if (
                item.IsWrite ||
                item.Name == '发布考试' ||
                item.Name == 'add/edit/del:room' ||
                item.Name == 'add/edit/del:mark' ||
                item.Name == 'add/edit/del:monitor' ||
                item.Name == 'add/edit/del:stu' ||
                item.Name == '审核'
              ) {
                this.operationList.push(item.Name);
                if (item.Name == 'add/edit/del:stu' && item.IsWrite) {
                  this.isShowAddStu = true;
                } else if (item.Name == '发布考试' && item.IsWrite) {
                  this.IsShowCancelPublic = true;
                }
              }
            });
            this.IsOpList = rst.list;
            // this.operationList = rst.list;
          }
          this.$http
            .post('/api/design/batch/getSysType', {
              batchId: this.$route.params.batchid
            })
            .then((rst) => {
              this.sysType = rst;
              this.getExamList();
            });
        } else {
          this.$message.error(rst.msg);
        }
      });
    },
    // 获取考试列表
    getExamList() {
      this.loading = true;
      this.$http
        .post('/api/design/workexam/getExamList', {
          title: this.examName,
          sortName: this.sortName,
          //setTime: this.selectType === '1' ? 1 : this.selectType === '0' ? 0 : '',
          setTime: this.selectType,
          timeType: this.timeType,
          examType: this.examType === '全部' ? '' : this.examType,
          batchId: this.$route.params.batchid,
          pageSize: this.pagenation.pageSize || 10,
          page: this.pagenation.current || 1
        })
        .then((rst) => {
          this.loading = false;
          this.examList = [];
          if (rst.code == 1) {
            this.isShowTestSchool = rst.isShow;
            this.examMode = rst.examMode;
            this.isXK = rst.isXk;
            this.batchTitle = rst.batchTitle;
            this.pagenation.current = rst.pagination.pageIndex;
            this.pagenation.pageSize = rst.pagination.pageSize;
            this.pagenation.total = rst.pagination.totalCount;
            if (rst.list.length) {
              rst.list.forEach((exam) => {
                let timeLength = '';
                let timeRepairLength = '';
                this.examList.push({
                  ...exam,
                  timeLength: this.initTime(exam.StartTime, exam.EndTime),
                  timeRepairLength: this.initTime(exam.RepairStartTime, exam.RepairEndTime)
                });
              });
            }
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    initTime(start, end) {
      let timeLength = '';
      let h = '';
      let m = '';
      let s = '';
      if (start && end) {
        let duringTime = (new Date(end).getTime() - new Date(start).getTime()) / 1000;
        h = Math.floor(duringTime / 3600);
        m = Math.floor((duringTime % 3600) / 60);
        s = Math.floor((duringTime % 3600) / 3600);
        let hString = h + '小时';
        var mString = '';
        if (m > 0) {
          mString = m + '分';
        } else {
          mString = '';
        }
        let sString = s + '秒';
        // return h ? hString : '' + m ? mString : '' + s ? sString : '';
        return h ? hString + '' + mString : mString;
      } else {
        return '--';
      }
    },
    addExam() {
      if (!this.getIsWrite('add/edit/del')) {
        return;
      }
      this.$router.push({
        name: 'addExam',
        parasm: {
          batchid: this.$route.params.batchid
        }
      });
    },
    addExamOne() {
      if (!this.getIsWrite('add/edit/del')) {
        return;
      };
      if (this.sysType == 2) {
        this.$router.push({
          name: 'addExamTwo',
          parasm: {
            batchid: this.$route.params.batchid
          }
        });
      } else {
        this.$router.push({
          name: 'addExamOne',
          parasm: {
            batchid: this.$route.params.batchid
          }
        });
      }
      
    },
    // 按照条件查询
    searchList() {
      this.getExamList();
    },
    // 清楚搜索
    clearSearch() {
      this.examType = '全部';
      this.selectType = '全部';
      (this.timeType = '全部'), (this.examName = '');
    },
    // 全选
    checkAllAction() {
      this.checkAll = !this.checkAll;
      this.defaultCheck = [];
      if (this.checkAll) {
        this.examList.forEach((item) => {
          this.defaultCheck.push(item.Id);
        });
      } else {
        this.defaultCheck = [];
      }
    },
    // 获取选中的id
    onChange(val) {
      this.checkAll = val.length === this.examList.length;
    },
    changePage(current, pageSize) {
      this.pagenation.current = current;
      this.pagenation.pageSize = pageSize;
      this.$nextTick(() => {
        this.getExamList();
      });
    },
    examRoom(val, type) {
      if (!this.getIsWrite(type)) {
        return;
      }
      this.$router.push({
        name: 'roomManagement',
        params: {
          batchid: this.$route.params.batchid,
          examid: val.Id
        }
      });
    },
    getDropAction(e, val, type) {
      if (!this.getIsWrite(type)) {
        return;
      }
      switch (e.key) {
        case '0':
          this.$router.push({
            name: 'editExam',
            params: {
              batchid: this.$route.params.batchid,
              examid: val.Id
            }
          });
          break;
        case '6':
          this.getStuManage(val, 1);
          break;
        case '1':
          this.getStuManage(val, 0);
          break;
        case '2':
          this.getProctorTeacher(val);
          break;
        case '3':
          this.getReviewTeacher(val);
          break;
        case '4':
          this.$router.push({
            name: 'testPaper',
            params: {
              examid: val.Id
            }
          });
          break;
        case '5':
          this.getAuditInfo(val);
          break;
        case '7':
          this.deleteExam([val.Id]);
          break;
        case '8':
          this.getIpInfo(val);
          break;
        case '11':
          this.getSaveKeepInfo(val);
          break;
        case '9':
          break;
        case '10':
          this.$router.push({
            name: 'roomManagement',
            params: {
              batchid: this.$route.params.batchid,
              examid: val.Id
            }
          });
          break;
        case '13':
          this.saveExamState(val, 0, '确认要归档该考试吗？归档后，该考试将不可以再进行修改，批阅等');
          break;
        case '14':
          this.examQuesAnswerId = val.Id;
          this.saveExamAnswer = true;
          this.synchronizedAnswers = val.SynchronizedAnswers;
          this.repairSynchronizedAnswers = val.RepairSynchronizedAnswers;
          break;
        default:
          break;
      }
    },
    //同步答案
    saveExamQuesAnswer(workexamType) {
      this.$confirm({
        title: '提示',
        content: '确定要同步该试卷的答案？（同步答案后，不可取消该操作。同步后就可以进行批阅操作了）',
        centered: true,
        onOk: () => {
          this.loading = true;
          this.$http
            .post('/api/design/workexam/saveAnswer', {
              workexamId: this.examQuesAnswerId,
              workexamType: workexamType
            })
            .then((rst) => {
              this.loading = false;
              if (rst.code == 1) {
                this.$message.success(rst.msg);
                this.saveExamAnswer = false;
                this.examQuesAnswerId = '';
                this.examQuesAnswerRepair = false;
              } else {
                this.$message.error(rst.msg);
              }
            });
        }
      });
    },
    //归档
    saveExamState(val, again, title) {
      this.$confirm({
        title: '提示',
        content: title,
        centered: true,
        onOk: () => {
          this.loading = true;
          this.$http
            .post('/api/design/workexam/saveExamState', {
              examid: val.Id,
              again: again
            })
            .then((rst) => {
              this.loading = false;
              if (rst.code == 1) {
                this.$message.success(rst.msg);
                this.getExamList();
              } else if (rst.code == -100) {
                this.saveExamState(
                  val,
                  1,
                  '该考试存在未批阅完成的学生作答记录，确认要归档该考试吗？归档后，该考试将不可以再进行修改，批阅等'
                );
              } else {
                this.$message.error(rst.msg);
              }
            });
        }
      });
    },
    // 考生管理
    getStuManage(val, paperType) {
      let newPage = this.$router.resolve({
        name: 'studentManage',
        params: {
          batchid: this.$route.params.batchid,
          examid: val.Id,
          paperType: paperType
        }
      });
      window.open(newPage.href, '_blank');
    },
    // 监考教师
    getProctorTeacher(val) {
      let newPage = this.$router.resolve({
        name: 'proctorTeacher',
        params: {
          batchid: this.$route.params.batchid,
          examid: val.Id
        }
      });
      window.open(newPage.href, '_blank');
    },
    // 批阅教师
    getReviewTeacher(val) {
      let newPage = this.$router.resolve({
        name: 'reviewTeacher',
        params: {
          batchid: this.$route.params.batchid,
          examid: val.Id
        }
      });
      window.open(newPage.href, '_blank');
    },
    examBtnsAction(val, type, data) {
      if (!this.getIsWrite(type)) {
        if (type == '监考管理') {
          if (!this.isXK) {
            return;
          }
        } else {
          return;
        }
      }
      let name = '';
      let params = '';
      switch (val) {
        case 1:
          name = 'pushExam';
          params = {
            batchid: this.$route.params.batchid,
            examid: data.Id
          };
          break;
        case 2:
          if (this.operationList.includes('监考管理')) {
            name = 'proctorManage';
          } else {
            name = 'proctorManage';
          }
          break;
        case 3:
          name = 'examAnalysis';
          params = {
            examid: data.Id
          };
          break;
        case 4:
          this.getReviewPaper(data);
          break;
        default:
          break;
      }
      if (name !== 'proctorManage') {
        this.$router.push({
          name,
          params: params
            ? params
            : {
                examid: data.Id
              }
        });
      } else if (name === 'proctorManage') {
        if (val == 2) {
          this.$http
            .post('/api/design/workexam/getHaveRepair', {
              examId: data.Id
            })
            .then((rst) => {
              if (rst.code > 0 && rst.isHaveRepair) {
                this.choice = true;
                this.paperId = data.Id;
              } else {
                //只是监考教师身份，如果存在补考发布则直接跳转补考卷监考,否跳转正式卷监考
                if (rst.isOnlyShowRepair) {
                  this.paperId = data.Id;
                  let newPage = this.$router.resolve({
                    name: 'proctorManage',
                    params: {
                      examid: data.Id,
                      paperType: 1
                    }
                  });
                  window.open(newPage.href, '_blank');
                } else {
                  this.paperId = data.Id;
                  let newPage = this.$router.resolve({
                    name: 'proctorManage',
                    params: {
                      examid: data.Id,
                      paperType: 0
                    }
                  });
                  window.open(newPage.href, '_blank');
                }
              }
            });
        } else {
          let newPage = this.$router.resolve({
            name: 'proctorManage',
            params: {
              examid: data.Id,
              paperType: 1
            }
          });
          window.open(newPage.href, '_blank');
        }
      }
    },
    // 一键编辑考试
    setExamStep(data) {
      localStorage.setItem('step', 0);
      if (this.sysType == 2) {
        this.$router.push({
          name: 'editExamTwo',
          params: {
            batchid: this.$route.params.batchid,
            examid: data.Id
          }
        });
      } else {
        this.$router.push({
          name: 'editExamOne',
          params: {
            batchid: this.$route.params.batchid,
            examid: data.Id
          }
        });
      }
      // let newPage = this.$router.push({
      //   name: 'editExamOne',
      //   params: {
      //     batchid: this.$route.params.batchid,
      //     examid: data.Id
      //   }
      // });
    },
    // 预览试卷
    getReviewPaper(data) {
      let newPage = this.$router.resolve({
        name: 'reviewPaper',
        params: {
          batchid: this.$route.params.batchid,
          examid: data.Id
        }
      });
      window.open(newPage.href, '_blank');
    },
    // 考试分析
    getExamAnalysis(data) {
      let newPage = this.$router.resolve({
        name: 'examAnalysis',
        params: {
          batchid: this.$route.params.batchid,
          examid: data.Id
        }
      });
      window.open(newPage.href, '_blank');
    },
    choicePaper(paperType) {
      let newPage = this.$router.resolve({
        name: 'proctorManage',
        params: {
          examid: this.paperId,
          paperType: paperType
        }
      });
      window.open(newPage.href, '_blank');
    },
    addCancel() {
      this.choice = false;
      this.paperId = '';
    },
    lookDetail(val, data) {
      let name = '';
      let params = '';
      switch (val) {
        case 1:
          name = 'approvaledList';
          params = {
            batchid: this.$route.params.batchid,
            examid: data.Id
          };
          break;
        case 2:
          name = 'notApprovaledList';
          params = {
            batchid: this.$route.params.batchid,
            examid: data.Id
          };
          break;
        case 3:
          name = 'unsubmittedList';
          params = {
            batchid: this.$route.params.batchid,
            examid: data.Id
          };
          break;
        default:
          break;
      }
      let newPage = this.$router.resolve({
        name: name,
        params: params
      });
      window.open(newPage.href, '_blank');
    },
    // 获取审核信息
    getAuditInfo(val) {
      let that = this;
      this.$http
        .post('/api/design/papermanage/getAuditInfo', {
          examId: val.Id
        })
        .then((res) => {
          if (res.code == 1) {
            this.isMine = res.isMine;
            this.auditList = res.teaList;
            this.isCanEditAudit = res.isCanEdit;
            this.sureRightItem = val;
            this.visible = true;
            if (!res.isCanEdit && res.checkType == 0) {
              this.chooseRadio = undefined;
            } else {
              that.chooseRadio = res.checkType == 2 ? 2 : 1;
              that.option = res.checkRemarks;
            }
          } else {
            this.$message.error(res.msg);
          }
        });
    },
    // 设置白名单
    setMenber(val, examId) {
      if (examId != '') {
        this.defaultCheck.push(examId);
      }
      if (!this.defaultCheck.length) {
        this.$message.error('请先选择你要设置的考试!');
        return;
      }
      if (val == 1) {
        this.setTitle = '设置白名单';
        this.setMenberVisible = true;
      } else if (val == 2) {
        this.setTitle = '设置黑名单';
        this.setMenberVisible = true;
      } else {
        this.chooseExamId = examId;
        this.CreateName = [];
        this.$http
          .post('/api/design/workExam/getRoleList', {
            key: this.selected,
            examId: examId
          })
          .then((res) => {
            this.addRole = true;
            this.selection = res.list;
            this.CreateName = res.roleList;
          });
      }
    },
    addRoleCancel() {
      this.mainTeacherIds = [];
      this.addRole = false;
    },
    selectTeacher(val) {
      this.mainTeacherIds = val;
    },
    saveRole() {
      this.loading = true;
      let { batchid } = this.$route.params;
      let ids = Array.prototype.slice.call(this.defaultCheck);
      this.$http
        .post('/api/design/workExam/saveWorkRole', {
          batchId: batchid,
          examIds: this.chooseExamId, //ids.length ? ids : this.clickExam.Id,
          roleIds: this.mainTeacherIds
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code > 0) {
            this.$message.success(rst.msg);
            this.defaultCheck = [];
            this.addRole = false;
            this.clickExam = '';
            this.mainTeacherIds = [];
            this.chooseExamId = '';
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    // 去除前后空格
    Trim(str) {
      return str.replace(/(^\s*)|(\s*$)/g, '');
    },
    // 确认设置白黑名单
    sureSet() {
      let type = 0;
      if (this.setTitle == '设置白名单') {
        type = 0;
      } else {
        type = 1;
      }
      // if (!this.Trim(this.setIps)) {
      //   this.$message.error('所填的地址不能为空');
      //   return;
      // }
      let { batchid } = this.$route.params;
      let ids = Array.prototype.slice.call(this.defaultCheck);
      this.loading = true;
      this.$http
        .post('/api/design/workexam/setIpList', {
          batchId: batchid,
          examIds: ids.length ? ids : this.clickExam.Id,
          ips: this.Trim(this.setIps),
          type
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code > 0) {
            this.$message.success(rst.msg);
            this.setIps = '';
            this.defaultCheck = [];
            this.setMenberVisible = false;
            this.clickExam = '';
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    getIpInfo(exam, type) {
      this.clickExam = exam;
      this.loading = true;
      this.$http
        .post('/api/design/workexam/getIpInfo', {
          examId: exam.Id,
          type: type ? type : 0
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code > 0) {
            this.setIps = rst.ips;
            this.setMenberVisible = true;
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    getCode() {
      this.$http.post('/api/design/workexam/getSaveKeepRandCode', {}).then((res) => {
        this.saveKeepCode = res;
      });
    },
    //获得封存信息
    getSaveKeepInfo(exam) {
      this.clickExam = exam;
      this.loading = true;
      this.$http
        .post('/api/design/workexam/getSaveKeepInfo', {
          examId: exam.Id
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code > 0) {
            this.saveKeepCode = rst.saveKeepCode;
            this.saveKeepType = rst.saveKeepType;
            this.setSaveKeepType = true;
            this.saveKeepList = rst.saveKeepList;
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    // 确认设置封存状态
    sureSetKeepType(type) {
      let ids = Array.prototype.slice.call(this.defaultCheck);
      this.loading = true;
      this.$http
        .post('/api/design/workexam/setSaveKeep', {
          examId: this.clickExam.Id,
          type: type,
          saveKeepCode: this.saveKeepCode
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code > 0) {
            this.$message.success(rst.msg);
            this.saveKeepCode = '';
            this.defaultCheck = [];
            this.setSaveKeepType = false;
            this.clickExam = '';
            this.getExamList();
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    // 手动关闭modeal出发的事件
    setClose() {
      this.setIps = '';
      this.clickExam = '';
      this.saveKeepCode = '';
    }
  }
};
</script>
